package cn.fl.tag.service.impl;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.tagext.TagSupport;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import cn.cmm.base.framework.context.ApplicationContextAccessor;
import cn.cmm.base.framework.utils.BaseLogUtils;
import cn.fl.framework.base.context.CurrentThreadContext;
import cn.fl.system.service.ISysResourceService;

/**
 * 资源权限
 * @author FUJINGRUN
 */
public class SysResourceAuthTag extends TagSupport{

	private static final long serialVersionUID = 5763601269572957972L;

	private static final Logger logger = LoggerFactory.getLogger(SysResourceAuthTag.class);
	
	/**
	 * 系统资源服务
	 */
	private ISysResourceService sysResourceService = (ISysResourceService)ApplicationContextAccessor.getBean("sysResourceServiceImpl");
	
	/**
	 * 功能资源代码
	 */
	private String resCd;
	
	@Override
	public int doStartTag() throws JspException {
		try {
			Boolean pass = sysResourceService.searchResourceWithAuth(CurrentThreadContext.getCurrentSysCd(), CurrentThreadContext.getCurrentRoleId(), getResCd());
			if(pass){
				return EVAL_BODY_INCLUDE;
			}else{
				return SKIP_BODY;
			}
		} catch (Exception e) {
			BaseLogUtils.error(logger, "", "获取资源权限错误!" + e.getCause().getMessage());
			return SKIP_BODY;
		}
	}

	/**
	 * 功能资源代码
	 */
	public String getResCd() {
		return resCd;
	}

	/**
	 * 功能资源代码
	 */
	public void setResCd(String resCd) {
		this.resCd = resCd;
	}
}
